package com.cn.yang.servlet.contactUs;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.contactUs.ContactUsModel;
import com.cn.yang.model.message.MessageModel;
import com.cn.yang.service.ContactUsService;
import com.cn.yang.service.MessageService;
import com.cn.yang.service.impl.ContactUsServiceImpl;
import com.cn.yang.service.impl.MessageServiceImpl;
import com.cn.yang.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/contactUs/findContactUs")
public class FindContactUsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        Integer pageSize = Integer.valueOf(req.getParameter("pageSize"));
        Integer pageNumber = Integer.valueOf(req.getParameter("pageNumber"));

        ContactUsService service = new ContactUsServiceImpl();
        PageUtil pageUtil = new PageUtil();
        pageUtil.setPageNumber(pageNumber);
        pageUtil.setPageSize(pageSize);
        ContactUsModel model = new ContactUsModel();
        model.setPageUtil(pageUtil);
        List<ContactUsModel> list = service.findContactUs(model);
        int count = service.countContactUs();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
